package site.luojie.sss.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import site.luojie.sss.pojo.Resume;
import site.luojie.sss.service.ResumeService;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author jie.luo
 * @Create: 2020-05-19 23:13
 **/
@Controller
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    /**
     * 查询列表
     */
    @PostMapping("/resumes")
    public String getAll(Map<String, Object> model) {
        List<Resume> resumes = resumeService.findAll();
        model.put("resumes", resumes);
        return "resumes";
    }

    /**
     * 根据Id查询
     */
    @GetMapping("/resume")
    public String findById(@RequestParam(required = false) Long id, Map<String, Object> model) {
        if (null != id){
            Resume byId = resumeService.findById(id);
            model.put("resume", byId);
        }
        return "resume";
    }

    /**
     * 删除
     */
    @PostMapping("/resume-del")
    public String delete(Long id) {
        resumeService.deleteResumeById(id);
        return "forward:resumes";
    }

    /**
     * 编辑
     */
    @PostMapping("/resume-modify")
    public String modify(Resume resume) {
        resumeService.saveResume(resume);
        return "forward:resumes";
    }

}
